package org.niu.sort;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;

public class SingleNumber
{
    public int[] singleNumber(int[] nums) {
        PriorityQueue<Map.Entry<Integer,Integer>> q = new PriorityQueue<>(new Comparator<Map.Entry<Integer, Integer>>() {
            @Override
            public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
                if(o1.getValue()!=o2.getValue()){
                    return o1.getValue()-o2.getValue();
                }
                return o1.getKey()-o2.getKey();
            }
        });
        Map<Integer,Integer> mp = new HashMap<>();
        for (int num : nums) {
            mp.put(num,mp.getOrDefault(num,0)+1);
        }
        q.addAll(mp.entrySet());
        int[] a = new int[]{q.poll().getKey(),q.poll().getKey()};
        return a;
    }
}
